﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ANZ_AIM_GUI.Utils;
using ANZ_AIM_BLL;
using ANZ_AIM_BLL.Model;
using log4net;

namespace ANZ_AIM_GUI
{
    public partial class frmCandidateVerifyStatus : Form
    {
        //log4net
        private static readonly ILog logger = LogManager.GetLogger(typeof(frmCandidateVerifyStatus));

        AppParam param = AppParam.Instance;

        public string batchFileID { get; set; }
        public frmCandidateVerifyStatus()
        {
            InitializeComponent();
        }

        public frmCandidateVerifyStatus(string batchFileID)
            : this()
        {
            try
            {
                this.batchFileID = batchFileID;
            }
            catch (Exception ex) { throw ex; }
        }


        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnVeriry_Click(object sender, EventArgs e)
        {
            var msg = String.Empty;
            try
            {
                msg = String.Format("{0}, batchFileID: {1}", Constant.SYS_MSG_CANDIDATE_VERIFY, batchFileID);

                BatchFileUploadBLL batchFileUploadBll = new BatchFileUploadBLL();
                batchFileUploadBll.UpdateStatus(batchFileID, Constant.NEED_TO_APPROVE);
                MessageBox.Show("Verify successfully.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
                return;
            }

            try
            {
                if (!String.IsNullOrEmpty(msg))
                {
                    LogBLL logBll = new LogBLL();
                    logBll.Description = msg;
                    logBll.Log(this.FindForm(), param.UserName);
                }
            }
            catch { }
        }

        private void btnReject_Click(object sender, EventArgs e)
        {
            var msg = String.Empty;
            try
            {
                msg = String.Format("{0}, batchFileID: {1}", Constant.SYS_MSG_CANDIDATE_REJECT, batchFileID);

                BatchFileUploadBLL batchFileUploadBll = new BatchFileUploadBLL();
                //batchFileUploadBll.Delete(batchFileID); //12Jan2015
                batchFileUploadBll.UpdateStatus(batchFileID, Constant.REJECTED); //12Jan2015

                CandidateBLL candidateBll = new CandidateBLL();
                candidateBll.Delete(batchFileID);

                MessageBox.Show("Reject successfully.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
                return;
            }

            try
            {
                if (!String.IsNullOrEmpty(msg))
                {
                    LogBLL logBll = new LogBLL();
                    logBll.Description = msg;
                    logBll.Log(this.FindForm(), param.UserName);
                }
            }
            catch { }
        }
    }
}
